﻿#!/bin/bash
#Log颜色处理-------------start
function infolog(){
    echo -e Log: "\033[32m$1\033[0m"
}

#输出报错log
function errorlog(){
    echo -e Error: "\033[01;31m$1\033[0m"
}

#输出报错log并停止运行
function errorlogExit(){
    echo -e Error: "\033[01;31m$1\033[0m"
    echo -e Error: "\033[01;31m打包失败\033[0m"
    exit
}

###获取当前脚步路径......
_CPath=$(pwd)
#echo "scriptPath1: "$(cd `dirname $0`; pwd)
#echo "scriptPath2: "$(pwd)
#echo "scriptPath4: "$(cd $(dirname ${BASH_SOURCE:-$0});pwd)

###获取当前时间......
_SDate=$(date +%Y.%m.%d_%H.%M.%S)




#_build="/Users/xia9000/work/2sign/test02/_build/";
#_unzipRootPath="/Users/xia9000/work/2sign/test02/_build/Payload/pingtai.app";
_xcode_ProjectPath=$1
infolog "_xcode_ProjectPath........${_xcode_ProjectPath}"
_outputPath=$2;
infolog "_outputPath......${_outputPath}"
_xcodeTemplate=$3
infolog "_xcodeTemplate......${_xcodeTemplate}"

#IPA导出路径


#清空之前的IPA
#cd ${EXPORT_PATH}
#rm -rf *

infolog "----------进入项目路径"${_xcode_ProjectPath}
cd ${_xcode_ProjectPath}

echo "1122" | sudo -S xcode-select -switch /Applications/Xcode.app
 

infolog "----------清空项目......."
#xcodebuild clean -quiet

#编译工程
xcodebuild archive -scheme ${_xcodeTemplate} -configuration "Release" -archivePath  ${_outputPath} -quiet || exit

infolog "----------ipa Xcode Project"

#cp ${_outputPath}"/Products/Applications/xcodeTemplate.app/Assets.car" ${_unzipRootPath}"/Assets.car"
#cp ${_outputPath}"/Products/Applications/xcodeTemplate.app/xcodeTemplate" ${_unzipRootPath}"/pingtai"
#cp ${_outputPath}"/Products/Applications/xcodeTemplate.app/PkgInfo" ${_unzipRootPath}"/PkgInfo"
#cp ${_outputPath}"/Products/Applications/xcodeTemplate.app/pingtai" ${_unzipRootPath}"/pingtai"


#rm -rf ${_outputPath}

#xcodebuild -exportArchive -archivePath ${_outputPath} -configuration "Release" -exportPath ${EXPORT_PATH} -exportOptionsPlist ${CONFIG_exportOptionsPlist} -quiet || exit

